//
//  NSDate+DateFormat.m
//  HouseSign
//
//  Created by 翁胜琼 on 2018/7/18.
//  Copyright © 2018年 bocweb. All rights reserved.
//

#import "NSDate+DateFormat.h"

@implementation NSDate (DateFormat)

// 2018-10-11 10:23:23
- (NSString *)getDateTimeString
{
    NSString *dateTimeString = [self getDateStringWithFormatter:@"yyyy-MM-dd HH:mm:ss"];
    
    return dateTimeString;
}

// 2018-10-11
- (NSString *)getDateString
{
    NSString *dateString = [self getDateStringWithFormatter:@"yyyy-MM-dd"];
    
    return dateString;
}

// 转换为时间字符串的指定方法
- (NSString *)getDateStringWithFormatter:(NSString *)formatter
{
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
    NSDateFormatter *format = [[NSDateFormatter alloc] init];
    [format setDateFormat:formatter];
    [format setTimeZone:timeZone];
    return [format stringFromDate:self];
}
@end
